package cn.nwpu.eckel.model;

import java.sql.Date;


import cn.nwpu.eckel.Dao.MPSDao;
import cn.nwpu.eckel.Dao.ScheduleReceiptDao;

public class ScheduleReceipt extends Source {
	public ScheduleReceipt(){
		this.id=0;
		this.mpsNo=0;
		this.ts=0;
		this.quantity=0;
		this.people="";
		this.buildTime=new Date(new java.util.Date().getTime());
	}
	public ScheduleReceipt(int mpsNo,int ts,int quantity,String people){
		this.mpsNo=mpsNo;
		this.ts=ts;
		this.quantity=quantity;
		this.people=people;
		this.buildTime=new Date(new java.util.Date().getTime());
	}
	public ScheduleReceipt(int id,int mpsNo,int ts,int quantity,String people){
		this.id=id;
		this.mpsNo=mpsNo;
		this.ts=ts;
		this.quantity=quantity;
		this.people=people;
	}
	public ScheduleReceipt(int id,int mpsNo,int ts,int quantity,String people,Date buildTime){
		this.id=id;
		this.mpsNo=mpsNo;
		this.ts=ts;
		this.quantity=quantity;
		this.people=people;
		this.buildTime=buildTime;
	}
	
	public void add(){
		ScheduleReceiptDao.insertScheduleReceipt(this);
	}
	
	public Source updateSelf(){
		Source s;
		s=ScheduleReceiptDao.alterScheduleReceipt(this);
		return s;
	}
	public void afterAdd(){
		MPS mps=MPSDao.getMPSById(this.mpsNo);
		mps.loadPlans();
		mps.p[this.ts].sr+=this.quantity;
		mps.calPlans();
		mps.savePlans();
	}
	public void afterDelete(){
		MPS mps=MPSDao.getMPSById(this.mpsNo);
		mps.loadPlans();
		mps.p[this.ts].sr-=this.quantity;
		mps.calPlans();
		mps.savePlans();
	}
	public void afterAlter(Source oldSr){
		MPS mps=MPSDao.getMPSById(this.mpsNo);
		mps.loadPlans();
		mps.p[this.ts].sr+=this.quantity-oldSr.quantity;
		mps.calPlans();
		mps.savePlans();
	}

}
